package com.ctshk.sapp.order.bus.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.rpc.order.bus.dto.BusInsuranceReceiptInfoDTO;
import com.ctshk.rpc.order.bus.service.IBusInsuranceReceiptService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "保单收据接口")
@RestController
@RequestMapping("/bus/insurance/receipt/")
public class BusInsuranceReceiptController {

	@DubboReference
	IBusInsuranceReceiptService busInsuranceReceiptService;
	
	@ApiOperation("根据订单ID查询保单收据信息")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "根据订单ID查询保单收据信息", operDesc = "根据订单ID查询保存收据信息")
	@GetMapping("findReceiptInfo/{orderId}")
	public Result<BusInsuranceReceiptInfoDTO> findReceiptInfo(@PathVariable Long orderId) {
		return busInsuranceReceiptService.findReceiptInfo(orderId);
	}
	
	@ApiOperation("下载保单收据")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "下载保单收据", operDesc = "下载保单收据")
    @GetMapping("downloadReceipt/{orderId}")
    public ResponseEntity<byte[]> downloadReceipt(@PathVariable Long orderId) {
    	byte[] body = "123".getBytes();
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", "attchement;filename=" + "123.pdf");
        HttpStatus statusCode = HttpStatus.OK;
        ResponseEntity<byte[]> entity = new ResponseEntity<byte[]>(body, headers, statusCode);
        return entity;
	}
    
    @ApiOperation("保单收据发送邮件")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "保单收据发送邮件", operDesc = "保单收据发送邮件")
    @GetMapping("sendEmailReceipt/{orderId}")
    public Result<Void> sendEmailReceipt(@PathVariable Long orderId) {
		return new Result<>();
	}
}
